package cn.itcast.controller;

import cn.itcast.domain.Standard;
import cn.itcast.service.StandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class StandardController {

    @Autowired
    private StandardService standardService;

    /**
     * 添加或修改
     * @param standard
     * @return
     */
    @RequestMapping("/standard_save")
    public String save(Standard standard){
        System.out.println(standard);
        standardService.save(standard);
        return "redirect:/pages/base/standard.html";
    }

    /**
     * 分页查询
     */
    @RequestMapping("/standard_pageQuery")
    @ResponseBody
    public Map pageQuery(int page, int rows){
        System.out.println("page="+page+",rows="+rows);
        Page<Standard> pageResult = standardService.pageQuery(page, rows);
        HashMap<String, Object> result = new HashMap<>();
        result.put("total",pageResult.getTotalElements());
        result.put("rows",pageResult.getContent());

        return result;
    }

    /**
     * 查询所有
     * @return
     */
    @RequestMapping("/standard_findAll")
    @ResponseBody
    public List<Standard> standardFindAll(){
        List<Standard> standard = standardService.standardFindAll();
        System.out.println("下拉框数据"+standard);
        return standard;
    }
}

